package com.glenet.salary.action;

import java.util.List;

import com.glenet.salary.dao.HrAgreementDao;
import com.glenet.salary.dao.HrCompanyDao;
import com.glenet.salary.dao.HrSubTemplateDao;
import com.glenet.salary.entities.HrAgreement;
import com.glenet.salary.entities.HrCompany;
import com.glenet.salary.entities.HrMap;
import com.glenet.salary.entities.HrSubTemplate;

@SuppressWarnings("serial")
public class HrCompanyAction extends BaseAction {

	private HrCompanyDao companyDao = new HrCompanyDao();
	private HrAgreementDao agreementDao = new HrAgreementDao();
	private HrSubTemplateDao subTemplateDao = new HrSubTemplateDao();
	private HrCompany company;
	private HrAgreement agreement;
	private Long id;
	
	public String get() throws Exception {
		company = companyDao.getCompany(id);
		return SUCCESS;
	}

	public String edit() throws Exception {
		company = companyDao.getCompany(id);
		return SUCCESS;
	}
	
	public String update() throws Exception {
		boolean flag = companyDao.update(company);
		return SUCCESS;
	}
	
	public String list() throws Exception {
		List<HrCompany> company_list =  companyDao.getCompany(0, Integer.MAX_VALUE);
		req.setAttribute("company_list", company_list);
		return SUCCESS;
	}
	
	public String delete() throws Exception {
		boolean flag = companyDao.delete(id);
		return SUCCESS;
	}
	
	public String add() throws Exception {
		List<HrMap> agreement_category = this.getMaps("AK");
		req.setAttribute("agreement_category", agreement_category);
		List<HrMap> agreement_state = this.getMaps("AJ");
		req.setAttribute("agreement_state", agreement_state);
		List<HrMap> banks = this.getMaps("AH");
		req.setAttribute("banks", banks);
		
		List<HrMap> unionPay = this.getMaps("AA");
		req.setAttribute("unionPay", unionPay);
		List<HrMap> serverPay = this.getMaps("AB");
		req.setAttribute("serverPay", serverPay);
		
		List<HrSubTemplate> tpl = subTemplateDao.list(0, Integer.MAX_VALUE);
		req.setAttribute("tpl", tpl);
		return SUCCESS;
	}

	public String save(){
		companyDao.save(company);
		System.out.println(agreementDao.save(agreement));
		return SUCCESS;
	}

	public HrCompany getCompany() {
		return company;
	}

	public void setCompany(HrCompany company) {
		this.company = company;
	}

	public HrAgreement getAgreement() {
		return agreement;
	}

	public void setAgreement(HrAgreement agreement) {
		this.agreement = agreement;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

}
